/**
 * Created by 83617 on 2019/1/11.
 */
var Society = require('../models/society')

exports.index = function(req,res){
    //console.log(req.session.user)
    //Society.fetch(function(err,societies){
    //    if(err) console.log(err)
    //    res.render('index',{
    //        title: '社团列表',
    //        societies: societies
    //    })
    //})
    var con = 2     //每页显示社团数
    var currentPage = 1
    Society.fetch(function(err,societies){
        if(err) console.log(err)
        var results = societies.slice(0,con)
        res.render('index',{
            title:'社团列表',
            societies:results,
            totalPage:Math.ceil(societies.length/con),
            currentPage:parseInt(currentPage,10),
            con:con
        })
    })
}

exports.pageSwitch = function(req,res){
    var con = parseInt(req.query.con,10)
    var page = req.query.page
    var index = con*(page-1)
    Society.fetch(function(err,societies){
        if(err) console.log(err)
        var results = societies.slice(index,index+con)

        res.render('index',{
            title:'社团列表',
            societies:results,
            totalPage:Math.ceil(societies.length/con),
            currentPage:parseInt(page,10),
            con:con
        })
    })
}
